
class Event(object):
    def __init__(self, event_type, event_data):
        self.type = event_type
        self.data = event_data

    def to_dict(self):
        return {
            "event_type": self.type,
            "event_data": self.data
        }

    def __repr__(self):
        return "EventData(%s)" % self.to_dict()


class Tick(object):
    def __init__(self,
                 symbol="",
                 trading_day="",
                 action_day="",
                 time="",
                 open_price=0.0,
                 high_price=0.0,
                 low_price=0.0,
                 last_price=0.0,
                 volume=0,
                 open_intl=0,
                 turnover=0.0,
                 avg_price=0.0,
                 upper_limit=0.0,
                 lower_limit=0.0,
                 settelment=0.0,
                 pre_close_price=0.0,
                 pre_settlement=0.0,
                 pre_open_intl=0,
                 decimal=0.01,
                 bid_price_1=0.0,
                 ask_price_1=0.0,
                 bid_volume_1=0,
                 ask_volume_1=0
                 ):
        self.symbol = symbol
        self.trading_day = trading_day
        self.action_day = action_day
        self.time = time

        self.open_price = open_price
        self.high_price = high_price
        self.low_price = low_price
        self.last_price = last_price
        self.upper_limit = upper_limit
        self.lower_limit = lower_limit

        self.volume = volume
        self.open_intl = open_intl
        self.turnover = turnover
        self.avg_Price = avg_price
        self.settlement = settelment

        self.pre_close_price = pre_close_price
        self.pre_settlement = pre_settlement
        self.pre_open_intl = pre_open_intl
        self.decimal = decimal

        self.bid_price_1 = bid_price_1
        self.bid_volume_1 = bid_volume_1

        self.ask_price_1 = ask_price_1
        self.ask_volume_1 = ask_volume_1

    def to_dict(self):
        return {
            "symbol": self.symbol,
            "trading_day": self.trading_day,
            "time": self.time,
            "open_price": self.open_price,
            "high_price": self.high_price,
            "low_price": self.low_price,
            "last_price": self.last_price,
            "uper_limit": self.upper_limit,
            "lower_limit": self.lower_limit,
            "volume": self.volume,
            "open_intl": self.open_intl,
            "turnover": self.turnover,
            "pre_close_price": self.pre_close_price
        }

    def log_str(self):
        return self

    def __repr__(self):
        return "Tick(%s)" % self.to_dict()


class Bar(object):
    def __init__(self,
                 symbol="",
                 date="",
                 time="",
                 open_price=0.0,
                 high_price=0.0,
                 low_price=0.0,
                 close_price=0.0,
                 upper_limit=0.0,
                 lower_limit=0.0,
                 volume=0,
                 open_intl=0
                 ):
        self.symbol = symbol
        self.date = date
        self.time = time
        self.open_price = open_price
        self.high_price = high_price
        self.low_price = low_price
        self.close_price = close_price
        self.upper_limit = upper_limit
        self.lower_limit = lower_limit

        self.volume = volume
        self.open_intl = open_intl

    def to_dict(self):
        return {
            "symbol": self.symbol,
            "date": self.date,
            "time": self.time,
            "open_price": self.open_price,
            "high_price": self.high_price,
            "low_price": self.low_price,
            "close_price": self.close_price,
            "upper_limit": self.upper_limit,
            "lower_limit": self.lower_limit,
            "volume": self.volume,
            "open_intl": self.open_intl,
        }

    def log_str(self):
        return self

    def __repr__(self):
        return "Tick(%s)" % self.to_dict()


class MDFieldNames(object):
    def __init__(self):
        self.symbol = "Symbol"
        self.instrument = "InstrumentID"
        self.trading_day = "TradingDay"
        self.action_day = "ActionDay"
        self.date = "Date"
        self.time = "Time"
        self.open_price = "Open"
        self.high_price = "High"
        self.low_price = "Low"
        self.close_price = "Close"
        self.last_price = "LastPx"
        self.upper_limit = "UpperLimit"
        self.lower_limit = "LowerLimit"
        self.volume = "Volume"
        self.open_intl = "OpenIntl"
        self.turnover = "Turnover"
        self.avg_Price = "AvgPx"
        self.settlement = "Settlement"
        self.pre_close_price = "PreClose"
        self.pre_settlement = "PreSettlement"
        self.pre_open_intl = "PreOpenIntl"
        self.bid_price_1 = "BidPx1"
        self.bid_volume_1 = "BidV1"
        self.ask_price_1 = "AskPx1"
        self.ask_volume_1 = "Askv1"


class Position(object):
    """
    用户持仓：目前只支持股票
    """
    def __init__(self):
        # 用户ID
        self.account_id = ''
        # 交易所内股票代码
        self.instrument_id = ''
        # 交易所
        self.exchange = ''
        # 股票名称
        self.name = ''
        # 当期持仓仓位
        self.current_qty = 0
        # 当前可卖仓位
        self.enable_qty = 0
        # 昨日仓位
        self.ytd_qty = 0
        # 交易本地冻结仓位
        self.frozen_qty = 0
        # 持仓成本均价
        self.cost_price = 0.0
        # 持仓盈亏
        self.position_pnl = 0.0
        # 手续费
        self.commission = 0.0
        # 最新交易日期
        self.trading_day = ''
        # 持仓市值
        self.markrt_value = 0.0
        # 股票最新价格
        self.last_price = 0.0


class Order(object):
    """
    订单：目前只支持股票
    """
    def __init__(self):
        self.account_id = ''
        self.instrument_id = ''
        self.exchange = ''
        # 订单数量
        self.order_qty = 0
        # 发单价格
        self.order_price = 0.0
        # 发单金额
        self.order_value = 0.0
        # 状态：已发出\回测引擎已接收
        self.order_status = ''


class Trade(object):
    """
    订单成交：目前只支持股票
    """
    def __init__(self):
        self.account_id = ''
        self.instrument_id = ''
        self.exchange = ''
        # 订单数量
        self.order_qty = 0
        # 发单价格
        self.order_price = 0.0
        # 状态：已发出\回测引擎已接收
        self.order_money = 0.0
        # 交易数量
        self.trade_qty = 0
        # 交易价格
        self.trade_price = 0.0
        # 交易资金
        self.trade_value = 0.0
        # 交易状态：未成交\部分成交\全部成交\部分取消\全部取消
        self.trade_status = ''


class AccountInfo(object):
    """
    账户信息：账号、密码等
    """
    def __init__(self, account_id, password, start_cash):
        self.account_id = account_id
        self.password = password
        self.start_cash = start_cash